<template>
  <div class="content">
  <el-tabs v-model="activeName2" type="card">
    <el-form label-width="">
        <el-form-item label="">
          <el-button type="primary" style="margin-left: 14px;" @click = "BulletinContentAdd()" id="BulletinContentAdd">发布公告</el-button>
        </el-form-item>
        <el-table :data="curriculumListData" border fit highlight-current-row style="width: 100%">
          <el-table-column align="center" label="公告标题" prop="title">
          </el-table-column>
          <el-table-column align="center" label="发布时间" prop="createdTime">
          </el-table-column>
          <el-table-column
          align="center"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" v-show="OPERATIONHide" @click="deleteClick(scope.row)">删除</el-button>
          </template>
        </el-table-column>
        </el-table>
      </el-form>
    </el-tabs>
  </div>
</template>

<script>
// import tabPane from '@/components/tabPane'
import axios from 'axios'
import api from "@/api/BulletinContent";
import { Message } from 'element-ui'
export default {
    data() {
      return {
        activeName2: 'first',
        list: [{
        mm: {
          nn: "mmmmm",
          kk: "3423",
          dd: "2323"
        },
        ii: "888"
      }],
      curriculumListData: [],
      materialData: [],
      demo: {
        name: ""
      },
      appsData: [],
      OPERATIONHide: true,
      curriculumListData: []
      };
    },
    mounted(){
      this.curriculumList()
      this.perimos()
    },
    methods: {
      // 权限设置
      perimos(){
        setTimeout(function(){
          let role = localStorage.getItem('role');
          if(role == '管理员' || role == '超级管理员') {
            return false;
          }
          if(role == '代理商') {
            document.getElementById('AgentManagement').style.dispaly = 'none';
            // document.getElementById('configure').style.dispaly = 'none';
            document.getElementById('upload').style.dispaly = 'none';
            // document.getElementById('BulletinContentAdd').style.display = 'none'

            // let buttonLength = document.getElementsByClassName('el-button');
            // for(var i =3;i<buttonLength.length;i++) {
            //   buttonLength[i].style.display = 'none'
            // }
          }
          if(role == '普通用户') {
            console.log(role)
            this.OPERATIONHide = false;
            document.getElementById('configure').style.dispaly = 'none';
            document.getElementById('BulletinContent').style.dispaly = 'block';
            document.getElementById('upload').style.dispaly = 'none';
            document.getElementById('BulletinContentAdd').style.display = 'none'
            let buttonLength = document.getElementsByClassName('el-button');
            for(var i =3;i<buttonLength.length;i++) {
              buttonLength[i].style.display = 'none'
            }
            // buttonLength.map((item,index) => {
            //   if(index != 0 || index != 1 || index != 2 || index != 3) {
            //     item[index].style.display = 'none'
            //   }
            // }) 
          }
        },50)
      },
      timeFormat(time) {
        var d = new Date(time); 
        var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()
        return times;
      },
      BulletinContentAdd() {
        this.$router.push('/BulletinContent/BulletinContentAdd')
      },
      curriculumList() {
        api.noticeList('/notice/query').then(response => {
          console.log(response)
          this.curriculumListData = response
          response.map((item, index) => {
            this.curriculumListData[index].createdTime = this.timeFormat(item.createdTime)
          })
        })
        if(localStorage.getItem('role') == '代理商') {
           
           this.$router.push('服务商管理')
            this.$store.dispatch('delOthersViews', '服务商管理').then(() => {
              this.moveToCurrentTag()
            })
            this.$router.push('/ServiceManagement')
            location.reload();
        }
      },
      deleteClick(tab, event){
        api.deleteList(tab.oid).then(response => {
          this.curriculumList()
        })
      },
      appAdd(){
        // this.$router.push('appAdd')
      },
    }
  }
</script>

<style scoped>
  .tab-container{
    margin: 30px;
  }
  .content {
    margin-left: 30px;
    margin-top: 30px;
  }
</style>
